<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符定位器</title>
    <style>
        body {
            font-family: 'Segoe UI', system-ui, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f8f9fa;
            margin: 0;
        }

        .container {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            width: 90%;
            max-width: 600px;
        }

        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 1.8rem;
            font-size: 1.8em;
        }

        .input-group {
            margin: 1.5rem 0;
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            color: #495057;
            font-weight: 500;
        }

        input[type="text"], 
        input[type="number"] {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 2px solid #dee2e6;
            border-radius: 6px;
            transition: border-color 0.3s;
        }

        input:focus {
            border-color: #4dabf7;
            outline: none;
        }

        button {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #4dabf7, #339af0);
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: transform 0.1s;
            margin-top: 1rem;
        }

        button:active {
            transform: scale(0.98);
        }

        #result {
            margin-top: 1.5rem;
            padding: 1.2rem;
            border-radius: 6px;
            font-size: 18px;
            text-align: center;
            display: none;
        }

        .success {
            background: #e7f5ff;
            border: 2px solid #4dabf7;
            color: #1864ab;
        }

        .error {
            background: #fff3cd;
            border: 2px solid #ffd351;
            color: #856404;
        }

        .char-display {
            font-size: 2em;
            font-weight: bold;
            margin: 10px 0;
            padding: 15px;
            background: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>字符位置查询器</h1>
        
        <div class="input-group">
            <label for="inputString">输入字符串：</label>
            <input type="text" id="inputString" placeholder="示例：Hello World">
        </div>
        
        <div class="input-group">
            <label for="inputIndex">输入位置序号：</label>
            <input type="number" id="inputIndex" placeholder="示例：3" min="1">
        </div>

        <button onclick="findCharacter()">查询字符</button>

        <div id="result">
            <div id="message"></div>
            <div class="char-display" id="charResult"></div>
        </div>
    </div>

    <script>
        function findCharacter() {
            // 获取输入元素
            const str = document.getElementById('inputString').value;
            const index = parseInt(document.getElementById('inputIndex').value);
            const resultDiv = document.getElementById('result');
            const messageDiv = document.getElementById('message');
            const charDiv = document.getElementById('charResult');

            // 重置状态
            resultDiv.style.display = 'block';
            resultDiv.className = '';
            charDiv.textContent = '';

            // 输入验证
            if (!str) {
                resultDiv.className = 'error';
                messageDiv.textContent = "⚠ 请输入有效字符串！";
                return;
            }

            if (isNaN(index) || index < 1) {
                resultDiv.className = 'error';
                messageDiv.textContent = "⚠ 请输入有效的正整数！";
                return;
            }

            if (index > str.length) {
                resultDiv.className = 'error';
                messageDiv.textContent = `⚠ 字符串长度只有 ${str.length}！`;
                return;
            }

            // 获取字符（索引从1开始）
            const targetChar = str.charAt(index - 1);
            
            // 显示结果
            resultDiv.className = 'success';
            messageDiv.textContent = `第 ${index} 个字符是：`;
            charDiv.textContent = targetChar === ' ' ? '␣（空格）' : targetChar;
        }
    </script>
</body>
</html>